<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Yy</title>
</head>

<body>
    <script>
        var arr = [];
        var res = [];
        var i;
        //1. 找出数组[1,3,4,6,7,8,11,12,15,16,19,20]中的所有奇数，并放在一个新数组中。
        arr = [1, 3, 4, 6, 7, 8, 11, 12, 15, 16, 19, 20];
        for (i of arr) {
            if (i % 2 == 1) {
                res.push(i);
            }
        }
        console.log(res);


        //2. 找出数组[4,6,1,2,3,7,5]中的最大值的索引。 
        arr = [4, 6, 1, 2, 3, 7, 5];
        var temp = arr[0];
        var index = 0;
        for (var i = 1; i < arr.length; i++) {
            temp = temp > arr[i] ? temp : arr[i];
            index = temp > arr[i] ? index : i;
        }
        console.log(temp, index);
    </script>
</body>

</html>